<?php
/*
* Copyright (c) 2017 Baidu.com, Inc. All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* Http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/

require_once 'lib/AipBase.php';

/**
 * 人脸检测
 */
class AipFace extends AipBase{

    /**
     * Api Url
     * @var string
     */
    private $detectUrl = 'https://aip.baidubce.com/rest/2.0/face/v1/detect';

    /**
     * @param  string $image 读取图像
     * @param  array $option 可选参数
     * @return array 检测结果
     * 
     */
    protected function detectApi($image, $options=array()){
        $headers = $this->getAuthHeaders('POST', $this->detectUrl);
        
        $params = array();
        if(!empty($this->accessToken)){
            $params['access_token'] = $this->accessToken;
        }

        $data = array();
        $data['image'] = base64_encode($image);
        $data['max_face_num'] = isset($options['max_face_num']) ? $options['max_face_num'] : '1';
        $data['face_fields'] = isset($options['face_fields']) ? $options['face_fields'] : '';

        return $this->client->post($this->detectUrl, $data, $params, $headers);

    }

}
